package com.houpu.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houpu.pojo.Product;
import com.houpu.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping(value = "product_name")
    public Map<String,Object> get_EA(int page,int limit,@PathVariable String p_name){
        System.out.println("前端的数据:"+p_name);
        PageHelper.startPage(page, limit);
        List<Product> eara = productService.get_Eara(p_name);
        PageInfo<Product> pageInfo = new PageInfo<>(eara, limit);
        HashMap<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("data", pageInfo.getList());
        result.put("count", pageInfo.getTotal());
        return result;
    }
}
